package com.shihb.behavioralpatterns.iteratorpattern;

import java.util.Iterator;

/**
 *Description:
 *Version:1.0.0
 *@author shihb
 *@date 2020/7/28 19:36
 */
public class InfoAggregation implements CollegeAggregation {
  private Department[] departments;
  private String name;
  private int index;
  public InfoAggregation() {
    name="信息工程";
    departments=new Department[5];
    index=0;
    setElement(new Department("信息管理"));
    setElement(new Department("信息分析"));
    setElement(new Department("信息随便"));
  }


  @Override
  public Iterator create() {
    return new InfoIterator(departments);
  }

  @Override
  public void setElement(Department department) {
    if(index < departments.length){
      departments[index]=department;
      index++;
    }
  }

  @Override
  public String getName() {
    return name;
  }
}
